<template>
  <!-- 热门岗位前10 -->
  <div class="barChart"></div>
</template>

<script>
import { getXueliJob } from "@/api/page2Api";
export default {
  name: "",
  data() {
    return {
      data: [],
      cityData: [],
      job1: [],
      job2: [],
      job3: [],
    };
  },
  props: {
    cData: Array,
  },
  watch: {
    cData(newValue) {
      // console.log(newValue,'11')
      this.setChart();
      // this.liveheader = newValue
    },
  },

  methods: {
    getData() {
      getXueliJob().then((res1) => {
        let res = res1.data.splice(0, 7);
        console.log(res, "hahahha22");
        if (res.length > 0) {
          this.jobData = [];
          this.job1 = [];
          this.job2 = [];
          this.job3 = [];
          res.forEach((item, index) => {
            if (item.length > 2) {
              this.jobData.push(item[0].job_name);
              this.job1.push(item[0].salary);
              this.job2.push(item[1].salary);
              this.job3.push(item[2].salary);
            }
          });
          console.log(this.job1, this.job2, this.job3);
          // this.data = res[1].map(item => ({name: item.xueli,value: item.salary}))
          this.setChart();
        }
      });
    },
    setChart() {
      let option = {
        xAxis: {
          type: "value",
          axisLabel: {
            color: "#fff",
          },
        },
        yAxis: {
          type: "category",
          axisLabel: {
            color: "#fff",
          },
          data: this.cData.map((item) => item.name),
        },
        series: [
          {
            data: this.cData.map((item) => item.salary),
            type: "bar",
            itemStyle: {
              color: "rgb(44,206,180)",
            },
          },
        ],
      };
      let myChart = this.$echarts(this.$el);

      myChart.clear();
      myChart.resize();
      myChart.setOption(option);
    },
  },
  mounted() {
    // this.getData();
  },
};
</script>

<style lang="less" scoped>
.barChart {
  width: 100%;
  height: 100%;
}
</style>